package com.tourism.product.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.common.security.utils.SecurityUtils;
import com.tourism.product.domain.TourismProduct;
import com.tourism.product.service.ITourismProductService;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 产品管理Controller
 * 
 * @author silenceEcho
 * @date 2025-04-12
 */
@RestController
public class TourismProductController extends BaseController
{
    @Autowired
    private ITourismProductService tourismProductService;

    /**
     * 查询产品管理列表
     */
    @RequiresPermissions("product:product:list")
    @GetMapping("/list")
    public TableDataInfo list(TourismProduct tourismProduct)
    {
        startPage();
        List<TourismProduct> list = tourismProductService.selectTourismProductList(tourismProduct);
        return getDataTable(list);
    }

    /**
     * 导出产品管理列表
     */
    @RequiresPermissions("product:product:export")
    @Log(title = "产品管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TourismProduct tourismProduct)
    {
        List<TourismProduct> list = tourismProductService.selectTourismProductList(tourismProduct);
        ExcelUtil<TourismProduct> util = new ExcelUtil<TourismProduct>(TourismProduct.class);
        util.exportExcel(response, list, "产品管理数据");
    }

    /**
     * 获取产品管理详细信息
     */
    @RequiresPermissions("product:product:query")
    @GetMapping(value = "/{productId}")
    public AjaxResult getInfo(@PathVariable("productId") Long productId)
    {
        return success(tourismProductService.selectTourismProductByProductId(productId));
    }

    /**
     * 新增产品管理
     */
    @RequiresPermissions("product:product:add")
    @Log(title = "产品管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TourismProduct tourismProduct)
    {
        tourismProduct.setCreateBy(SecurityUtils.getUsername());
        tourismProduct.setUpdateBy(SecurityUtils.getUsername());
        return toAjax(tourismProductService.insertTourismProduct(tourismProduct));
    }

    /**
     * 修改产品管理
     */
    @RequiresPermissions("product:product:edit")
    @Log(title = "产品管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TourismProduct tourismProduct)
    {
        tourismProduct.setUpdateBy(SecurityUtils.getUsername());
        return toAjax(tourismProductService.updateTourismProduct(tourismProduct));
    }

    /**
     * 删除产品管理
     */
    @RequiresPermissions("product:product:remove")
    @Log(title = "产品管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{productIds}")
    public AjaxResult remove(@PathVariable Long[] productIds)
    {
        return toAjax(tourismProductService.deleteTourismProductByProductIds(productIds));
    }
}
